import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import Axios from 'axios'

// 引入公共样式文件
import './assets/common.css'

// 完整引入elementUI
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
Vue.use(ElementUI);

// 引入下载好的阿里矢量字体图标
import './assets/iconfont/iconfont.css'

// 引入全屏插件
import screenfull from 'screenfull'
Vue.prototype.$screenfull = screenfull;

// 引入引导页插件
import Driver from 'driver.js'
import 'driver.js/dist/driver.min.css'
Vue.prototype.$driver = Driver

// 引入animate.css
import animated from 'animate.css/animate.css'
Vue.use(animated);

// 图片预览插件 vue-photo-preview
import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
Vue.use(preview)

// vue 编码但不渲染的标签 vue-fragment
// 主要解决递归菜单栏组件递归后不能折叠问题
import Fragment from 'vue-fragment'
Vue.use(Fragment.Plugin)

// 引入echarts
const echarts = require('echarts'); 
Vue.prototype.$echarts = echarts;

// 引入全局自定义过滤器
import * as filter from './assets/filter'
Object.keys(filter).forEach((key) => {
  Vue.filter(key, filter[key]);
});

// 引入全局自定义指令
import * as directive from './assets/directive'
Object.keys(directive).forEach((key) => {
  Vue.directive(key, directive[key]);
});

// 全局前置导航守卫
router.beforeEach((to,from,next)=>{
  // 让浏览器显示页面标题
  const title = to.meta && to.meta.title;
  if(title){
    document.title = title;
  }
  next();
})


import utils from '@/common/js/utils.js'
import verify from '@/common/js/verify.js'
import mixin from '@/common/js/mixin.js'
import Filter from '@/common/js/filter.js'


Object.keys(Filter).forEach(key => Vue.filter(key, Filter[key]))
Vue.mixin(mixin)


const obj = {
  utils,
  verify
}

for (const key in obj) {
  Object.defineProperty(Vue.prototype, `$${key}`, {
    get: () => obj[key]
  })
}


Vue.prototype.axios = Axios;


if(location.href.indexOf('jbk')!=-1){
  Vue.prototype.$domain = 'https://jbk.maoyishiji.com/index.php'
  Vue.prototype.$baseUrl = 'https://jbk.maoyishiji.com'
  Vue.prototype.$env = 'prodect'
}else{
  Vue.prototype.$domain = 'http://www.gold.com/index.php'
  Vue.prototype.$baseUrl = 'http://www.gold.com'
  Vue.prototype.$env = 'dev'
}


Vue.prototype.$post = function (url, data, callback) {
    var _this = this
	let user_name = sessionStorage.getItem('user_name')
	let token = sessionStorage.getItem('token')
	
    if (url.indexOf('http') == -1) {
        url = this.$domain + url
    }
	
     _this.axios.post(url, data,{
		 headers: {
		   Authorization:token
	     }
	 }).then(function (res) {
        var call = callback || function (res) {}
        if(res.data.code==401){
			ElementUI.Message({
			  message:'请从新登录',
			  type:'error'
			})
          _this.$router.push('/')
        }else if(res.data.code==400){
          ElementUI.Message({
			  message:res.data.msg,
			  type:'error'
		  })
        }else{
			 call(res)
		}
		 // loading.close()
     })
}



Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
